<!-- default.vue -->
<template>
  <navbar :config="navConfig"></navbar>
  <slot></slot>
  <tabbar v-model="currentTabbar"></tabbar>
</template>

<script lang="ts" setup>
import {ref, computed} from "vue";
import {onShow} from "@dcloudio/uni-app";
import {TABBAR_DATA} from '@/components/tabbar/config'
import tabbar from "@/components/tabbar/index.vue";
import navbar from "@/components/navbar.vue";

const currentTabbar = ref(0)

const navConfig = computed(() => {
  let showLeftArrow = false
  let pages = getCurrentPages();
  let page = pages[pages.length - 1];

  if (pages.length > 1) showLeftArrow = true
  return {
    title: page.$page.meta?.navigationBar?.titleText,
    showLeftArrow,
  }
})

// 在页面显示时更新 currentTabbar
onShow(() => {
  const currentPagePath = getCurrentPages()[getCurrentPages().length - 1].route;
  if (currentPagePath === TABBAR_DATA[0].path.substring(1)) {
    currentTabbar.value = 0;
  } else if (currentPagePath === TABBAR_DATA[1].path.substring(1)) {
    currentTabbar.value = 1;
  }
});

</script>

<style lang="scss" scoped>

</style>